import pandas as pd
from pandas import DataFrame
from sklearn.cluster import DBSCAN
from sklearn.metrics import calinski_harabasz_score,silhouette_score
import numpy as np
import matplotlib.pyplot as plt

datafile = './文本/客运量_1-16.csv' 
datafile2 = './文本/货运量_1-16.csv' 
data = pd.DataFrame(pd.read_csv(datafile))
data2 = pd.DataFrame(pd.read_csv(datafile2))

data3 = data
data = data.drop(['机场名'], axis=1)#删除第一列机场名

train = np.array(data) 
dbscan = DBSCAN(eps=5000000,min_samples=1).fit(train)
data3['labels'] = dbscan.labels_#新建列labels
data2['labels'] = dbscan.labels_#新建列labels
data3.to_csv(datafile,index=False,encoding='utf_8_sig')
data2.to_csv(datafile2,index=False,encoding='utf_8_sig')